//
//  TYZRequest.h
//  DrivieSchoolStudents
//
//  Created by TangBin on 2019/5/29.
//  Copyright © 2019 班文政. All rights reserved.
//

#import "TYZBaseRequest.h"

NS_ASSUME_NONNULL_BEGIN








FOUNDATION_EXPORT NSString *const TYZRequestCacheErrorDomain; ///< 缓存错误的时候

NS_ENUM(NSInteger)
{
    TYZRequestCacheErrorExpired = -1,  ///< 缓存过期了
    TYZRequestCacheErrorVersionMismatch = -2, ///< 版本不匹配
    TYZRequestCacheErrorSensitiveDataMismatch = -3, ///< 敏感数据不匹配
    TYZRequestCacheErrorAppVersionMismatch = -4, ///< 应用程序版本不匹配
    TYZRequestCacheErrorInvalidCacheTime = -5, ///< 无效的缓存时间
    TYZRequestCacheErrorInvalidMetadata = -6,   ///< 无效的元数据
    TYZRequestCacheErrorInvalidCacheData = -7, ///< 无效的缓存数据
};

/**
 本来继承TYZBaseRequest 本类主要功能是用来缓存的
 */
@interface TYZRequest : TYZBaseRequest

/// 忽略缓存
@property (nonatomic, assign) BOOL ignoreCache;

/**
 数据是否来自本地缓存。

 @return return value description
 */
- (BOOL)isDataFromCache;

///  Manually load cache from storage.
///
///  @param error If an error occurred causing cache loading failed, an error object will be passed, otherwise NULL.
///
///  @return Whether cache is successfully loaded.
- (BOOL)loadCacheWithError:(NSError * __autoreleasing *)error;

/**
 启动请求时不读取本地缓存，即使它存在。使用它来更新本地缓存。
 */
- (void)startWithoutCache;

///  Save response data (probably from another request) to this request's cache location
- (void)saveResponseDataToCacheFile:(NSData *)data;

#pragma mark - Subclass Override

/**
 缓存在被认为过期之前可以停留在磁盘上的最长时间。
 默认值是-1，这意味着响应实际上没有保存为缓存。

 @return return value description
 */
- (NSInteger)cacheTimeInSeconds;

/**
 版本可用于标识和使本地缓存无效。默认值为0。

 @return return value description
 */
- (long long)cacheVersion;


/**
 缓存敏感数据

 @return return value description
 */
- (nullable id)cacheSensitiveData;

/**
 缓存是否异步写入存储。默认是YES。

 @return return value
 */
- (BOOL)writeCacheAsynchronously;

@end

NS_ASSUME_NONNULL_END





















